import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();
        while (t > 0) {
            t--;
            int n = scanner.nextInt();
            String str = scanner.next();
            //构造ABABABAB..., BABABABA...字符串
            StringBuilder stringBuilder1 = new StringBuilder();
            StringBuilder stringBuilder2 = new StringBuilder();
            for (int i = 0; i < 2 * n; i++) {
                if (i % 2 == 0) {
                    stringBuilder1.append('A');
                    stringBuilder2.append('B');
                } else {
                    stringBuilder1.append('B');
                    stringBuilder2.append('A');
                }
            }
            String str1 = stringBuilder1.toString();//ABABAB
            String str2 = stringBuilder2.toString();//BABABA

            int count1 = 0, count2 = 0;

            for (int i = 0; i < 2 * n; i++) {
                if (str.charAt(i) != str1.charAt(i)) {
                    count1++;
                } else if (str.charAt(i) != str2.charAt(i)) {
                    count2++;
                }
            }

            System.out.println(Math.min(count1 / 2, count2 / 2));
        }

        scanner.close();
    }
}
